#ifndef _BSP_I2C_SLAVE_H_
#define _BSP_I2C_SLAVE_H_
#include "bsp_gpio.h"
#include "sym32l010_hal_i2c.h"
#define TX_LEN 100
#define RX_LEN 100

#define I2C_MD_MASTER 0
#define I2C_MD_SLAVE 1

#define MASTER_I2C_START    0x08
#define MASTER_I2C_RESTART  0x10
#define MASTER_I2C_WR_DEVADDR_ACK   0x18
#define MASTER_I2C_WR_DEVADDR_NAK  0x20
#define MASTER_I2C_WR_DR_ACK   0x28
#define MASTER_I2C_WR_DR_NAK   0x30
#define MASTER_ARBITRATION_LOST 0x38
#define MASTER_I2C_RD_DEVADDR_ACK   0x40
#define MASTER_I2C_RD_DEVADDR_NAK  0x48
#define MASTER_I2C_RD_DR_ACK   0x50
#define MASTER_I2C_RD_DR_NAK   0x58
#define MASTER_I2C_ERROR  0x00

#define SLAVE_I2C_WR_DEVADDR_ACK   0x60
#define SLAVE_I2C_WR_DEVADDR_NAK  0x68
#define SLAVE_I2C_RD_DR_ACK   0x80
#define SLAVE_I2C_RD_DR_NAK   0x88
#define SLAVE_I2C_STOP_RESTART   0xA0
#define SLAVE_I2C_RD_DEVADDR_ACK   0x80
#define SLAVE_I2C_RD_DEVADDR_NAK  0x88
#define SLAVE_I2C_WR_DR_ACK   0xB8
#define SLAVE_I2C_WR_DR_NAK   0xC0
#define SLAVE_WR_DR_ACK      0xC8
#define SLAVE_I2C_ERROR  0x00

#define I2C_WRITE 0
#define I2C_READ 1

#define I2C_AA_ACK  1
#define I2C_AA_NAK  0
typedef struct
{
    bsp_gpio_init_t* gpio_sda;
    bsp_gpio_init_t* gpio_scl;
    uint8_t i2c_mode;
    uint32_t baudrate;
    uint8_t slaveaddr1;
    uint8_t slaveaddr2;
    uint8_t slaveaddr3;
    uint8_t *txbuf;
    uint8_t *rxbuf;
}bsp_i2c_init_t;

typedef struct
{
    uint8_t devAddr;
    uint8_t RW;
    uint8_t *preg;
    uint8_t reglen;
    uint8_t *pdata;
    uint16_t len;
    uint16_t txcnt;
    uint16_t rxcnt;
    uint8_t regcnt;
}bsp_i2c_msg_t;

extern uint8_t I2C1_txbuf[TX_LEN],I2C1_rxbuf[RX_LEN];
void BSP_I2C_Slave_Int_Callback(void);
int32_t BSP_I2C_Slave_Init(bsp_i2c_init_t *pI2CInit);
int32_t BSP_I2C_Slave_DeInit(bsp_i2c_init_t *pI2CInit);



#endif /* _BSP_I2C_SLAVE_H_ */
